import { Form, DatePicker } from 'antd';
import React from 'react';
import { todayMoment, today } from '../../utils/moment';

export const DateRangePickerForm = (
  { 
    form, 
    field='date_range',
    onChange, 
    values 
  }) => {
  const { RangePicker } = DatePicker;
  const dateFormat = 'YYYY-MM-DD';
  let { startTime, endTime } = values || {};

  if (!startTime || !endTime) {
    startTime = endTime = today();
  }

  return (
    <Form.Item>
      {form.getFieldDecorator(field, {
        initialValue: [moment(startTime, dateFormat), moment(endTime, dateFormat)]
      })(
        <RangePicker 
          onChange={onChange}
          format={dateFormat}
          placeholder={['开始时间','结束时间']}
          />
      )}
    </Form.Item>
  );
}